﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace spktNhom4DoAnCuoiKy.UserModules
{
    public partial class Payment : System.Web.UI.Page
    {
        AuctionOnlineDataContext db = new AuctionOnlineDataContext();
        string FomatCurrency(double amount)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.CurrencySymbol = "";
            nfi.CurrencyDecimalDigits = 2;
            nfi.CurrencyDecimalSeparator = ".";
            nfi.CurrencyGroupSeparator = ",";

            return String.Format(nfi, "{0:C0}", amount);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtMaGiaoDich.Text = Request.QueryString["c"];
                if (txtMaGiaoDich.Text != "")
                {
                    string username = db.LichSuThanhToans.Where(x => x.MaGiaoDich == txtMaGiaoDich.Text).FirstOrDefault().UserThanhToan;
                    txtUsername.Text = username;
                    
                }
                Session["SoTienThanhToan"] = null;
            }
            
        }

        protected void btnLayThongTin_Click(object sender, EventArgs e)
        {
            lblMaGiaoDich.Text = txtMaGiaoDich.Text;
            var ls = db.LichSuThanhToans.Where(x => x.MaGiaoDich == txtMaGiaoDich.Text).FirstOrDefault();
            if (ls != null)
            {
                lblSoTienThanhToan.Text = FomatCurrency(ls.SoTienThanhToan.Value);
                lblMaPhien.Text = ls.MaPhien;
                Session["SoTienThanhToan"] = ls.SoTienThanhToan;
            }
            
        }
        //kiem tra
        int thanhtoan(string magiaodich, string mathe, string loaithe, string matkhau, double sotien,ref string thongbao)
        {
            thongbao= "Giao dịch được thanh toán thành công.";
            return 1;
        }
        protected void btnThanhToan_Click(object sender, EventArgs e)
        {
            string thongbao = "";
            if (Session["SoTienThanhToan"] != null)
            {
                int response = thanhtoan(lblMaGiaoDich.Text, "9e830", "visacard", "12423", (double)Session["SoTienThanhToan"], ref thongbao);
                lblThongBao.Text = thongbao;
                Button2_ModalPopupExtender.Show();
            }
            else return;

        }
    }
}